package com.bwie.lib_core.network;
/**
 * 单例获取retrofit对象的工厂
 * */
public class HttpRetrofitFactory {

    private HttpRetrofitFactory(){}

    private static HttpRetrofitFactory instance;

    public static HttpRetrofitFactory getInstance(){
        if (instance == null)
            instance = new HttpRetrofitFactory();
        return instance;
    }

    private HttpRetrofit interfaceRetrofitImpl;//请求接口httpRetrofitImpl
    private HttpRetrofit uploadRetrofitImpl;//上传httpretrofitimpl
    private HttpRetrofit signInterfaceRetrofitImpl;//只有sign无token拦截器的建造者
    private HttpRetrofit tokenInterfaceRetrofitImpl;//只有token无sign拦截器的建造者
    public HttpRetrofit factory(HttpType type){
        if (type == HttpType.INTERFACE){
            if (interfaceRetrofitImpl == null) {
                InterfaceHttpRetrofitImpl.InterfaceHttpRetrofitBuilder builder = new InterfaceHttpRetrofitImpl.InterfaceHttpRetrofitBuilder();
                interfaceRetrofitImpl = builder.build();
            }
            return interfaceRetrofitImpl;
        }
        if (type == HttpType.UPLOAD){
            if (uploadRetrofitImpl == null){
                UploadHttpRetrofitImpl.UploadHttpRetrofitBuilder builder = new UploadHttpRetrofitImpl.UploadHttpRetrofitBuilder();
                uploadRetrofitImpl = builder.build();
            }
            return uploadRetrofitImpl;
        }
        if (type == HttpType.SIGNINTERFACE){
            if (signInterfaceRetrofitImpl == null){
                SignInterfaceHttpRetrofitImpl.SignInterfaceHttpRetrofitBuilder builder = new SignInterfaceHttpRetrofitImpl.SignInterfaceHttpRetrofitBuilder();
                signInterfaceRetrofitImpl = builder.build();
            }
            return signInterfaceRetrofitImpl;
        }
        if (type == HttpType.TOKENINTERFACE){
            if (tokenInterfaceRetrofitImpl == null){
                TokenInterfaceHttpRetrofitImpl.TokenInterfaceHttpRetrofitBuilder builder =
                        new TokenInterfaceHttpRetrofitImpl.TokenInterfaceHttpRetrofitBuilder();
                tokenInterfaceRetrofitImpl = builder.build();
            }
            return tokenInterfaceRetrofitImpl;
        }
        return null;
    }

}
